"use strict";
const nodemailer = require("nodemailer");
const user = {
  user: "1299475789@qq.com",
  pass: "eqslzoujdtnngccf",
}


//创建传输对象
let transporter = nodemailer.createTransport({
  host: "smtp.qq.com",
  port: 465,
  secure: true, // true for 465, false for other ports
  auth: {
    ...user,
  },
});

function sendMail(email) {
  let code=getCode();
  transporter.sendMail({
    from: '"xiaotao" <1299475789@qq.com>', // 发送人的账号
    to: email, //接收人的账号
    subject: "您正在登录苏宁易购", // Subject line

    html: `<b>亲爱的"小涛"您的验证码是:${code}</b>`, // html body
  });
  return code;
}

function random(min, max) {
  return Math.ceil(Math.random() * (max - min + 1) + min - 1);
}

function getCode() {
  let code = '';
  let type;
  for (let i = 0; i < 6; i++) {
    type = random(1, 3);
    switch (type) {
      case 1:
        code += String.fromCharCode(random(48, 57));
        break;
      case 2:
        code += String.fromCharCode(random(65, 90));
        break;
      case 3:
        code += String.fromCharCode(random(97, 122));
        break;
    }
  }
  return code;
}
module.exports = {sendMail};


  

  

 